﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 新增加班申请表初步 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "SupportingDocumentId",
                table: "SysHrTransferRequestBill",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "CompOffHours",
                table: "SysDailyCompOffRequestBill",
                type: "decimal(8,2)",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "CompOffType",
                table: "SysDailyCompOffRequestBill",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<string>(
                name: "OvertimeRequestBillIds",
                table: "SysDailyCompOffRequestBill",
                type: "nvarchar(2000)",
                maxLength: 2000,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "SysDailyOvertimeRequestBill",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PersonId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    StaffNo = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    StartTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    EndTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    OvertimeHours = table.Column<decimal>(type: "decimal(8,2)", nullable: false),
                    CompensationType = table.Column<int>(type: "int", nullable: false),
                    RemainingCompOffHours = table.Column<decimal>(type: "decimal(8,2)", nullable: true),
                    Reason = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    UpdateBy = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Approver = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    ApprovalTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    GroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    OrgId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    BillCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    BillStatus = table.Column<int>(type: "int", nullable: true),
                    WorkflowStatus = table.Column<int>(type: "int", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysDailyOvertimeRequestBill", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysDailyOvertimeRequestBill_FrameworkGroups_GroupId",
                        column: x => x.GroupId,
                        principalTable: "FrameworkGroups",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysDailyOvertimeRequestBill_SysOrg_OrgId",
                        column: x => x.OrgId,
                        principalTable: "SysOrg",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysDailyOvertimeRequestBill_SysPerson_PersonId",
                        column: x => x.PersonId,
                        principalTable: "SysPerson",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_SysHrTransferRequestBill_SupportingDocumentId",
                table: "SysHrTransferRequestBill",
                column: "SupportingDocumentId");

            migrationBuilder.CreateIndex(
                name: "IX_SysDailyOvertimeRequestBill_GroupId",
                table: "SysDailyOvertimeRequestBill",
                column: "GroupId");

            migrationBuilder.CreateIndex(
                name: "IX_SysDailyOvertimeRequestBill_OrgId",
                table: "SysDailyOvertimeRequestBill",
                column: "OrgId");

            migrationBuilder.CreateIndex(
                name: "IX_SysDailyOvertimeRequestBill_PersonId",
                table: "SysDailyOvertimeRequestBill",
                column: "PersonId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrTransferRequestBill_FileAttachments_SupportingDocumentId",
                table: "SysHrTransferRequestBill",
                column: "SupportingDocumentId",
                principalTable: "FileAttachments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysHrTransferRequestBill_FileAttachments_SupportingDocumentId",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropTable(
                name: "SysDailyOvertimeRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrTransferRequestBill_SupportingDocumentId",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropColumn(
                name: "SupportingDocumentId",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropColumn(
                name: "CompOffHours",
                table: "SysDailyCompOffRequestBill");

            migrationBuilder.DropColumn(
                name: "CompOffType",
                table: "SysDailyCompOffRequestBill");

            migrationBuilder.DropColumn(
                name: "OvertimeRequestBillIds",
                table: "SysDailyCompOffRequestBill");
        }
    }
}
